<template>
  <div class="login-page">
    <el-card>
      <template #header>

          <div class="clearfix">
            <span>90叼毛管理运营后台</span>
          </div>
      </template>
          <el-form ref="form" :model="form" :rules="rules" autocomplete="off">

            <el-form-item label="用户名" prop="username">
              <el-input placeholder="请输入账户名" v-model="form.username"></el-input>
            </el-form-item>

            <el-form-item label="密码" prop="password">
              <el-input placeholder="请输入密码" v-model="form.password"></el-input>
            </el-form-item>

            <el-form-item class="tc">
              <el-button @click="login" type="primary">登录</el-button>
              <el-button @click="resetForm('form')">重置</el-button>
            </el-form-item>
          </el-form>

    </el-card>
  </div>
</template>

<script>
// import { gogin } from '@/api/user'
export default {
  name: 'LoginIndex',
  data () {
    return {
      form: {
        username: '',
        password: ''
      },
      rules: {
        username: [
          { required: true, message: '请输入正确的账户名', trigger: ['blur', 'change'] },
          { min: 3, max: 11, message: '长0度在 3 到 18 个字符', trigger: ['blur', 'change'] }
        ],
        password: [
          { required: true, message: '请输入正确的密码', trigger: ['blur', 'change'] },
          { pattern: /^\w{5,16}$/, message: '长度在 5 到 18 位的密码', trigger: ['blur', 'change'] }
        ]
      }
    }
  },
  methods: {
    // async login () {
    //   this.$refs.form.sayHi()
    //   try {
    //     const valid = await this.$refs.form.validate()
    //     console.log(valid)
    //   } catch (e) {
    //     console.log(e)
    //   }
    // },
    login () {
      this.$refs.form.validate(async valid => {
        if (!valid) return
        console.log('我要登录')
        await this.$store.dispatch('user/loginAction', this.form)
        // gogin('username', 'password')
        this.$router.push('/')
        this.$message.success('登录成功')
      })
    },
    resetForm (formName) {
      this.$refs[formName].resetFields()
    }
  }
}
</script>

<style lang="scss" scoped>
.login-page {
  min-height: 100vh;
  background: url(@/assets/login-bg.svg) no-repeat center / cover;
  display: flex;
  align-items: center;
  justify-content: space-around;
  .el-card {
    width: 420px;
    ::v-deep .el-card__header{
      height: 80px;
      background: #fb7299;
      text-align: center;
      line-height: 40px;
      color: #fff;
      font-size: 18px;
    }
  }
  .el-form {
    padding: 0 20px;
  }
  .tc {
    text-align: center;
  }
}
</style>
